package com.sinosoft.dsp.platform.utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.faces.model.SelectItem;

import com.sinosoft.dsp.platform.services.CodeSetService;
import com.sinosoft.dsp.system.core.i18n.BaseMessages;
import com.sinosoft.dsp.system.core.log.Log;

@SuppressWarnings("unchecked")
public class UserOrgMap extends HashMap implements Map {

	private static final long serialVersionUID = 1L;

	private static final Log log = Log.getLog(UserOrgMap.class.getName());

	public static final String SYSTEM_CODE_SET_PREFIX = "__system.";

	private static final String PKG = "com.sinosoft.dsp.platform";

	public static final String CODESET_YESORNO_YES_VALUE = "1";
	public static final String CODESET_YESORNO_NO_VALUE = "0";

	private boolean initSystem = false;

	@Override
	public Object get(Object key) {
		try {
			if (!initSystem && key instanceof String
					&& ((String) key).startsWith(SYSTEM_CODE_SET_PREFIX)) {
				initSystemCodeSet();
				initSystem = true;
			}

			if (!super.containsKey(key)) {
				String idAndType = (String) key;
				String[] params = idAndType.split(",");

				CodeSetService css = SinoManagedBean.findBean("codeSetService");
				if ("select".equals(params[2])) {
					//super.put(key, css.getRootSubUserOrgSelectItems(params[0],params[1]));
				}  
			}
			return super.get(key);
		} catch (Exception e) {
			log.error("UserOrgMap: 获得用户部门的对象出现错误。");
		}
		return null;
	}

	private void initSystemCodeSet() {
		// 是否
		List<SelectItem> yesOrNo = new ArrayList<SelectItem>();
		yesOrNo.add(new SelectItem(CODESET_YESORNO_YES_VALUE, BaseMessages
				.getString(PKG, "service.codeset.common.yesOrNo.yes.label")));
		yesOrNo.add(new SelectItem(CODESET_YESORNO_NO_VALUE, BaseMessages
				.getString(PKG, "service.codeset.common.yesOrNo.no.label")));
	}
}
